package android.explorer.activity;

import java.io.File;

import myultility.Convert;
import myultility.Exec;

import android.app.Activity;
import android.content.Intent;
import android.explorer.FileExtendsionManager;
import android.explorer.R;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class FileProperties extends Activity{
	TextView tvT;
	String permission="rwxrwxrwxrwx",filename;
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate( savedInstanceState );
		setContentView( R.layout.fileproperties );
		filename = this.getIntent().getExtras().getString("filename");
		File file=new File(filename);
		setTitle(file.getName()+" properties");
		((TextView)findViewById(R.id.filepropertiesname)).setText("File name : "+file.getName());
		((TextView)findViewById(R.id.filepropertiesdir)).setText("Parent : "+file.getParent());
		((TextView)findViewById(R.id.filepropertiessize)).setText("File size : "+file.length()+" bytes");
		FileExtendsionManager.filter(file.getName());
		(tvT=(TextView)findViewById(R.id.filepropertiestype)).setText("File type : "+FileExtendsionManager.fileType);
		((ImageView)findViewById(R.id.filepropertiesicon)).setImageResource(FileExtendsionManager.fileIcon);
	
		Exec exe;
		exe=new Exec(new String[] {"ls","-l","-d",file.getAbsolutePath()});
		
		if(exe.exe(100))
		{
			((TextView)findViewById(R.id.fileproperties_owner)).setText("Owner : "+Convert.toPermission(exe.result.substring(1,4)));
			((TextView)findViewById(R.id.fileproperties_group)).setText("Group owner : "+Convert.toPermission(exe.result.substring(4, 7)));
			((TextView)findViewById(R.id.fileproperties_everyone)).setText("Other : "+Convert.toPermission(exe.result.substring(7, 10)));
			permission=exe.result.substring(1, 10);
			Log.v("debug", "permission " + permission);
			char c=exe.result.substring(1, 10).charAt(0);
			if(c=='l')
			{
				tvT.setText(tvT.getText()+" (Link)");
			}
			else if(c=='b')
			{
				tvT.setText(tvT.getText()+" (Binary)");
			}
		}
		else
		{
			this.setTitle(exe.error);
		}
	}
	
	public void onChangeButtonClick(View target) 
	{
		Intent intent=new Intent(this,android.explorer.activity.ChangePermission.class);
		intent.putExtra("filename",filename);
		intent.putExtra("permission", permission);
		Log.v("debug","permission: " + permission );
		startActivityForResult(intent,0);
	}
	public void onOkButtonClick(View target) {
		finish();
	}
}
